package Test01;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author 彪哥
 * @version 1.0
 */
public class Test {
    public static void main(String[] args) {
        ArrayList list = new ArrayList<Book>();
        boolean Button = true;
        while (Button) {
            //打印菜单
            System.out.println("--------欢迎来到【老马书城】-------");
            System.out.println("1.展示书籍");
            System.out.println("2.上新书籍");
            System.out.println("3.下架书籍");
            System.out.println("4.退出应用");
            //引入Sannner类
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入您想要执行的功能的序号：");
            int choice = sc.nextInt();    //键盘录入数据后，点击回车，程序才会接收数据

            //根据choice接收的功能序号进行后续判断
            switch (choice) {
                case 1:
                    System.out.println("【老马书城】>>>>>>>>1.展示书籍");
                    for (int i = 0; i < list.size(); i++) {
                        Book b = (Book)(list.get(i));
                        System.out.println(b.toString());
                    }
                    break;
                case 2:
                    System.out.println("【老马书城】>>>>>>>>2.上新书籍");
                    Book book = new Book();
                    System.out.println("请输入书籍编号：");
                    book.setBookID(sc.nextInt());
                    System.out.println("请输入书籍名称：");
                    book.setBookName(sc.next());
                    System.out.println("请输入书籍作者：");
                    book.setBookAuthor(sc.next());
                    list.add(book);
                    break;
                case 3:
                    System.out.println("【老马书城】>>>>>>>>3.下架书籍");
                    System.out.println("请输入要下架的书籍编号:");
                    int delNo = sc.nextInt();
                    for (int i = 0; i < list.size(); i++) {
                        Book b = (Book)(list.get(i));
                        if (delNo == b.getBookID()) {
                            list.remove(b);
                            System.out.println("书籍下架成功！");
                            break;
                        }
                    }
                    break;
                case 4:
                    System.out.println("【老马书城】>>>>>>>>4.退出应用");
                    Button = false;
                    break;
            }


        }
    }


}
